package Compare;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Objects;
import java.lang.Comparable;
import java.util.PriorityQueue;

class Card implements Comparable<Card>{
    public String suit;
    public int rank;
    public Card(String suit,int rank){
        this.suit =suit;
        this.rank = rank;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }

    @Override
    public int hashCode() {
        return Objects.hash(suit, rank);
    }

    @Override
    public int compareTo(Card o) {
        if (o==null){
            return 0;
        }
        return rank - o.rank;

    }

    @Override
    public String toString() {
        return "Card{" +
                "suit='" + suit + '\'' +
                ", rank=" + rank +
                '}';
    }

    public static void main(String[] args) {
        Card p = new Card("♠", 3);
        Card q = new Card("♠",6 );
        Card o = new Card("♠",9 );
        System.out.println(p.compareTo(o)); // == 0，表示牌相等
        System.out.println(p.compareTo(q)); // < 0，表示 p 比较小
        System.out.println(q.compareTo(p)); // > 0，表示 q 比较大
    }

}
class  SuitCompare implements Comparator<Card> {
    @Override
    public int compare(Card o1, Card o2) {
        return o1.suit.compareTo(o2.suit);
    }
}
public class Test2  {
    public static void main2(String[] args) {
        PriorityQueue<Card> p =new PriorityQueue<>();
        p.offer(new Card("hongtao",6));
        PriorityQueue<Card> p1 =new PriorityQueue<>();
        p1.offer(new Card("hongtao",7));
        System.out.println(p1==p);

    }

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        int[] arr ={1,2,3,4};
        Card card1 = new Card("黑桃",9);
        Card card2 = new Card("红桃",10);
        if(card1.compareTo(card2)>0){
            System.out.println("card1>card2");
    }else {
            System.out.println("card1<=card2");
        }
        System.out.println("====================");
        SuitCompare suitCompare = new SuitCompare();
        if (suitCompare.compare(card1,card2)>0){
            System.out.println("card1>card2");
        }else{
            System.out.println("card1<=card2");
        }
    }

    public static void main1(String[] args) {
        Card card1 =new Card("红方块",7);
        Card card2 = new Card("黑方块",6);
        System.out.println(card1.equals(card2));
    }

}

